package net.hn.hnms.biz.indicator.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.indicator.entity.*;
import net.hn.hnms.biz.indicator.entity.SysIndicatorModel;
import net.hn.hnms.biz.indicator.entity.SysIndicatorModelDto;
import net.hn.hnms.biz.indicator.service.DwsMineMathematicalModelService;
import net.hn.hnms.biz.indicator.service.SysIndicatorBaseDataService;
import net.hn.hnms.biz.indicator.service.SysIndicatorModelService;
import net.hn.hnms.biz.indicator.service.SysIndicatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * @author 智呈物联 nzw
 * @date 2022/8/23
 */
@RestController
@RequestMapping("safety/indicator/model")
@Api(value = "指标模型", tags = {"指标模型"})
public class IndicatorModelController {

    private SysIndicatorModelService sysIndicatorModelService;

    private SysIndicatorBaseDataService sysIndicatorBaseDataService;

    private SysIndicatorService sysIndicatorService;

    private DwsMineMathematicalModelService dwsMineMathematicalModelService;

    @Autowired
    public void setSysIndicatorService(SysIndicatorService sysIndicatorService) {
        this.sysIndicatorService = sysIndicatorService;
    }

    @Autowired
    public void setDwsMineMathematicalModelService(DwsMineMathematicalModelService dwsMineMathematicalModelService) {
        this.dwsMineMathematicalModelService = dwsMineMathematicalModelService;
    }

    @Autowired
    public void setSysIndicatorModelService(SysIndicatorModelService sysIndicatorModelService) {
        this.sysIndicatorModelService = sysIndicatorModelService;
    }

    @Autowired
    public void setSysIndicatorBaseDataService(SysIndicatorBaseDataService sysIndicatorBaseDataService) {
        this.sysIndicatorBaseDataService = sysIndicatorBaseDataService;
    }


//    @ApiOperation(value = "获取分页或list数据", position = 1)
//    @GetMapping
//    public ResponseEntity<Object> pageList(String name, Pageable pageable) {
//        return ResponseEntity.ok(sysIndicatorModelService.pageList(name, pageable));
//    }

    @PostMapping
    @ApiOperation("指标模型添加")
    public ResponseEntity<Map<String,Object>> add(@RequestBody SysIndicatorModel sysIndicatorModel) {
        Map<String,Object> map = sysIndicatorModelService.save(sysIndicatorModel);
        return new ResponseEntity<Map<String,Object>>(map, HttpStatus.OK);
    }

    @ApiOperation("指标模型修改")
    @PostMapping("/edit")
    public ResponseEntity<Boolean> edit(@RequestBody SysIndicatorModelDto sysIndicatorModelDto) {
        boolean edit = sysIndicatorModelService.saveDto(sysIndicatorModelDto);
        return new ResponseEntity<Boolean>(edit, HttpStatus.OK);
    }

    @ApiOperation("指标模型删除")
    @GetMapping("/remove")
    public ResponseEntity<Boolean> remove(
            @NotNull String indicatorFirstLevelCode,
            @NotNull String indicatorSecondLevelCode) {
        boolean edit = sysIndicatorModelService.remove(indicatorSecondLevelCode, indicatorFirstLevelCode);
        return new ResponseEntity<Boolean>(edit, HttpStatus.OK);
    }


}
